<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>博以至客会员</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/xadmin.css">
    <script src="../layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../component/js/xadmin.js"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body class="layui-layout-body">
<!--    <input type="hidden" name="token" th:value="${session.token}">-->
<div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a href="">演示</a>
                <a>
                    <cite>导航元素</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<br>
<br>
<div class="layui-upload">
    <button type="button" class="layui-btn" id="test1">上传头像</button>
    <div class="layui-upload-list">
        <img th:src="'https://blog-cxz.oss-cn-beijing.aliyuncs.com/'+${studySrc.srcName}+'.jpg'" style="height: 200px;width: 200px;border-radius:100px;" id="demo1" >
        <p id="demoText"></p>
    </div>
</div>
<div>
    <section class="msg-remark">
        <form class="layui-form" action=""  >
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <div class="layui-input-block">
                    <input  type="hidden" id="srcId" name="srcId" required lay-verify="required" placeholder="请输入好友id"  autocomplete="off" class="layui-input" th:value="${studySrc.srcId}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">资料的科目名:</label>
                <div class="layui-input-block">
                    <input type="text" id="srcName"  name="srcName" required lay-verify="required" placeholder="请输入资料的科目名" autocomplete="off" class="layui-input" th:value="${studySrc.srcName}">
                </div>
            </div>
            <br>
            <br>
            <div class="layui-form-item">
                <label class="layui-form-label">资料链接:</label>
                <div class="layui-input-block">
                    <input type="text" id="srcUrl"  name="srcUrl" required lay-verify="required" placeholder="请输入资料链接" autocomplete="off" class="layui-input" th:value="${studySrc.srcUrl}">
                </div>
            </div>
            <br>
            <div class="layui-form-item">
                <label class="layui-form-label">资料密码:</label>
                <div class="layui-input-block">
                    <input type="text" id="srcPsw" name="srcPsw" required lay-verify="required" placeholder="请输入资料密码" autocomplete="off" class="layui-input" th:value="${studySrc.srcPsw}">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="hidden" id="hasNew" name="hasNew" required lay-verify="required" placeholder="请输入是否有新资料" autocomplete="off" class="layui-input" th:value="${studySrc.hasNew}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">资料的内容简介:</label>
                <div class="layui-input-block">
                    <input type="text" id="srcBrief" name="srcBrief" required lay-verify="required" placeholder="请输入资料的内容简介" autocomplete="off" class="layui-input" th:value="${studySrc.srcBrief}">
                </div>
            </div>
            <br>
            <div class="layui-form-item">
                <label class="layui-form-label">资料的目录结构:</label>
                <div class="layui-input-block">
                    <input type="text" id="srcMenu" name="srcMenu" required lay-verify="required" placeholder="请输入资料的目录结构" autocomplete="off" class="layui-input" th:value="${studySrc.srcMenu}">
                </div>
            </div>
            <br>
            <div class="layui-form-item">
                <label class="layui-form-label">资料的类型:</label>
                <div class="layui-input-block">
                    <input type="text" id="srcType" name="srcType" required lay-verify="required" placeholder="请输入资料的类型" autocomplete="off" class="layui-input" th:value="${studySrc.srcType}">
                </div>
            </div>
            <br>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button id="submit1"  type="button" data-type="reload" class="layui-btn layui-btn-primary">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </section>
</div>
<script src="../component/js/jquery-3.3.1.js"></script>
<script src="../layui/layui.js"></script>
<script src="../js/yss/gloable.js"></script>
<script src="../js/plugins/nprogress.js"></script>
<script>NProgress.start();</script>
<script src="../js/pagemessage.js"></script>
<script>NProgress.start();</script>
<script>
    window.onload = function () {
        NProgress.done();
    };
</script>
<script th:inline="javascript">
    layui.use(['upload', 'element', 'layer','form', 'layedit', 'laydate'], function() {
        var $ = layui.jquery
            , upload = layui.upload
            , element = layui.element
            , layer = layui.layer
            ,form = layui.form
            ,layedit = layui.layedit
            ,laydate = layui.laydate;
        //日期
        laydate.render({
            elem: '#user_birthday'
        });
        //常规使用 - 普通图片上传
        var uploadInst = upload.render({
                elem: '#test1'
                , url: '/oss/study?fileName='+[[${studySrc.srcName}]] //改成您自己的上传接口
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#demo1').attr('src', result); //图片链接（base64）
                    });

                    element.progress('demo', '0%'); //进度条复位
                    layer.msg('上传中', {icon: 16, time: 1});
                }
                , done: function (res) {
                    if(res.code > 0){
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #4cae4c;">上传成功</span>');

                    var fileupload = $(".image");
                    fileupload.attr("value",res.data.src);
                    console.log(fileupload.attr("value"));
                    window.parent.location.reload();
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            }
        )
    });
</script>
<script  th:inline="javascript">
    layui.use('form', function() {
        var form = layui.form;
        $("#submit1").on("click", function () {
            $.ajax({
                type:'post',
                url:'/study/updateStudySrc',
                data:{srcId:$("#srcId").val(),srcName:$("#srcName").val(),srcUrl:$("#srcUrl").val(),srcPsw:$("#srcPsw").val(),hasNew:$("#hasNew").val(),srcBrief:$("#srcBrief").val(),srcMenu:$("#srcMenu").val(),srcType:$("#srcType").val()},
                success:function (data) {
                    if (data.msg == 200 ){
                        layer.confirm('修改成功!')

                    }else {
                        layer.confirm('修改失败!')
                    }

                },
                error:function () {
                    layer.confirm('修改失败!')
                }
            })

        })
    });
</script>
</body>
</html>